package com.application.lucky.activity.me;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.application.lucky.R;
import com.application.lucky.activity.KeFuActivity;
import com.application.lucky.activity.PbChatActivity;
import com.application.lucky.bean.jsonBean.RecharTypeBean;
import com.application.lucky.config.Config;
import com.application.lucky.request.CallBackEx;
import com.application.lucky.request.RedPRequest;
import com.application.lucky.widget.TitlebarView;
import com.application.mylibrary.base.BaseActivity;
import com.application.mylibrary.utils.ToastUtils;
import com.baselib.libnetwork.net.libnetworkcomponent.BaseResponse;
import com.qunar.im.base.common.ConversitionType;

public class NewRechargeActivity extends BaseActivity {

    private TitlebarView mTitleBar;
    private ImageView mIvRechargeType;
    private TextView mIvRechargeName;
    private TextView mIvRechargeAccount;
    private TextView mIvRechargeAccount1;
    private TextView mIvRechargeAccount2,mIvRechargeAccount3;
    private TextView mTv;
    private TextView mTvRechargeKefu;
    private ImageView mIv;
    private String[] accounts = {"wx_11111111", "zfb_2222222", "yhk_33333333"};
    private int[] icons = {R.drawable.icon_recharge_wx, R.drawable.icon_recharge_zfb, R.drawable.icon_cash_card};
    private String[] titles = {"请直接转账微信账号", "请直接转账支付宝账号", "请直接转账银行卡账号"};
    private int type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    @Override
    public void beforeInit() {
        type = getIntent().getIntExtra("type", 0);

    }

    private ClipboardManager cm;
    private ClipData mClipData;

    @Override
    public int getLayoutId() {
        return R.layout.activity_new_recharge;
    }

    private void initView() {

        mTitleBar = (TitlebarView) findViewById(R.id.title_bar);
        mTitleBar.setOnViewClick(new TitlebarView.onViewClick() {
            @Override
            public void leftClick() {
                finishAnim();
            }

            @Override
            public void rightClick() {

            }
        });
        mIvRechargeType = (ImageView) findViewById(R.id.iv_recharge_type);
        mIvRechargeType.setImageResource(icons[type]);
        mIvRechargeName = (TextView) findViewById(R.id.iv_recharge_name);
        mIvRechargeName.setText(titles[type]);
        mIvRechargeAccount = (TextView) findViewById(R.id.iv_recharge_account);
        mIvRechargeAccount1 = (TextView) findViewById(R.id.iv_recharge_account1);
        mIvRechargeAccount2= (TextView) findViewById(R.id.iv_recharge_account2);
        mIvRechargeAccount3= (TextView) findViewById(R.id.iv_recharge_account3);
        mIvRechargeAccount.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
// 创建普通字符型ClipData
                mClipData = ClipData.newPlainText("Label", mIvRechargeAccount.getText().toString());
// 将ClipData内容放到系统剪贴板里。
                cm.setPrimaryClip(mClipData);
                ToastUtils.show("复制成功");

                return false;
            }
        });

        mTv = (TextView) findViewById(R.id.tv);
        mTvRechargeKefu = (TextView) findViewById(R.id.tv_recharge_kefu);
        mTvRechargeKefu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(NewRechargeActivity.this, PbChatActivity.class);
                intent.putExtra(PbChatActivity.KEY_JID, Config.IMIdUtils.getIMUid(Config.KEFU_ID));
                intent.putExtra(PbChatActivity.KEY_CHAT_TYPE, String.valueOf(ConversitionType.MSG_TYPE_CHAT));
                intent.putExtra(PbChatActivity.KEY_IS_CHATROOM, false);
                startActivity(intent);
//                startActivityAnim(new Intent(NewRechargeActivity.this, KeFuActivity.class));
            }
        });
        mIv = (ImageView) findViewById(R.id.iv);


        loadInfo();
    }

    private void loadInfo() {
        new RedPRequest().red_recharge_info(new CallBackEx<BaseResponse<RecharTypeBean>>() {
            @Override
            public void onSuccess(BaseResponse<RecharTypeBean> recharTypeBeanBaseResponse) {
                RecharTypeBean bean = recharTypeBeanBaseResponse.dataInfo;
                if (bean!=null) {
                    if (type == 0) {
                        mIvRechargeAccount.setText(bean.webChatPay);
                    } else if (type == 1) {
                        mIvRechargeAccount.setText(bean.aliPay);
                    } else {
                        String bank = bean.bank;
                        JSONObject object = JSON.parseObject(bank);
                        /**
                         *  public String name;
                         *         public String bankNo;
                         *         public String bankName;
                         *         public String banAddress;
                         */
                        String name = object.getString("name");
                        String bankNo = object.getString("bankNo");
                        String bankName = object.getString("bankName");
//                        String banAddress = object.getString("banAddress");
//                        RecharTypeBean.BankBean bankBean = bean.bank;
//                        if (bankBean!=null) {
                            mIvRechargeAccount.setText(bankNo);
                            mIvRechargeAccount1.setText(bankName);
//                            mIvRechargeAccount2.setText(banAddress);
                            mIvRechargeAccount3.setText(name);
                            mIvRechargeAccount1.setVisibility(View.VISIBLE);
//                            mIvRechargeAccount2.setVisibility(View.VISIBLE);
                            mIvRechargeAccount3.setVisibility(View.VISIBLE);
//                        }
                    }
                }

            }

            @Override
            public void onFailed(int code) {

            }
        });
    }
}
